/*
 * @ author madman
 * @ use nexmo类
 */
const server = require('./server');
const Utils = require('./index.js');
import axios from 'axios';
var objApi = {
  api_key: '289e6a50',
  api_secret: '28xQbIsYyTCx4Wb5'
}
export default {
  // 获取所有的电话号码
  numberList(data) {
    var params= { params: { ...objApi, ...data }}
    return server.get('account/numbers', params)
  },
  // 取消电话号码
  numberCancel(data) {
    var params= { params: { ...objApi, ...data }}
    return server.get('number/cancel', params)
  },
  // 获取指定国家
  getPricing(data, type) {
    var params= { params: { ...objApi, ...data }}
    return server.get('account/get-pricing/outbound/'+type, params)
  },
  // 获取所有国家的价格数据
  getFullPricing(data,type) {
    var params= { params: { ...objApi, ...data }}
    return server.get('account/get-full-pricing/outbound/'+type, params)
  },
  // 获取账户余额
  getBalance(data) {
    var params= { params: { ...objApi, ...data }}
    return server.get('account/get-balance', params)
  },
  //号码搜索
  numberSearch(data) {
    var params= { params: { ...objApi, ...data }}
    return server.get('number/search', params)
  },
  // 获取电话列表
  userList(data) {
    // console.log('data_1_'+data.token)
    return axios({
        method: 'get',
        url: 'https://api.nexmo.com/beta/users',
        data: {},
        headers: {
          'Authorization': 'Bearer ' + data.token,
          'Content-Type': 'application/json'
        }
    })
  },
  // 设置主叫电话号码
  setupNumber(data) {
    return server.post('number/update?api_key='+objApi.api_key+'&api_secret='+objApi.api_secret+'&country='+data.country+'&msisdn='+data.msisdn + '&voiceCallbackType=app&voiceCallbackValue=16763a08-8c51-44a9-9933-1e7a5716c1d7', {},{
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    })
  },
  // 取消电话
  numberCancel(data) {
    return server.post('number/cancel?api_key='+objApi.api_key+'&api_secret='+objApi.api_secret+'&country='+data.country+'&msisdn='+data.msisdn, {},{
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    })
  },
  // 购买电话卡
  numberBuy(data) {
    // var opttions = {
    //   'country': data.country,
    //   'msisdn': data.msisdn
    // }
    // console.log(opttions)
    return server.post('number/buy?api_key='+objApi.api_key+'&api_secret='+objApi.api_secret+'&country='+data.country+'&msisdn='+data.msisdn, {}, {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    })
  }
}